package queries;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import entitys.Product;
import enums.Result;

public class AddProductQuery {
/**
 * Execute query
 * @param p
 * @param conn
 * @return
 */
	public static Result exe(Product p,java.sql.Connection conn)
	{
		Statement stmt;
		ResultSet res;
		try {
			stmt = conn.createStatement();
			res = stmt.executeQuery("SELECT * FROM ccrm.product WHERE product.name='"+p.getName()+"';");
			if(res.next()) return Result.FAILED;
			
			stmt = conn.createStatement();
			stmt.executeUpdate("INSERT INTO `ccrm`.`product` (`name`,`description`,`picture`,`price`) "
					+ "VALUES ('"+p.getName() +"','"+p.getDescription() +"','"+p.getPicturen()+"',"+p.getPrice() +");");
			return Result.OK;
		
			
			
	 		
		} catch (SQLException e) {	return Result.ERROR;}
		
		
	}


}
